(function(){
	'use strict';
	angular.module('services.workOrderData.publishMgmt')
	.factory('publishStatisticFactory',publishStatisticFactory);
	function publishStatisticFactory(Restangular){
		return {
			query: query,
			getEchartsData: getEchartsData
		};
		function query(params,callback){
			Restangular.all('sas/workOrderData/publishMgmt/query').post(params).then(callback);
		}
		function getEchartsData(items,title){
			var temp = {
				xData:[],
				legendName:['发布版本总数','一次性通过版本数','打回次数','一次性通过率'],
				totalNum:[],
				num:[],
				backNum:[],
				passRate:[],
				seriesData:[]
			};
			angular.forEach(items,function(item){
				temp.xData.push(item.sysName);
				temp.totalNum.push(item.totalNum);
				temp.num.push(item.num);
				temp.backNum.push(item.backNum);
				temp.passRate.push(Number(item.passRate.substring(0,item.passRate.length -1)).toFixed(2));
			});
			return {
        title: {
          text: title,
          x: 'center'
        },
        animation: false,
        tooltip: {
          show: true
        },
        grid: {
          x2: 170
        },
        legend: {
          data: temp.legendName,
          orient: 'vertical',
          x: 'right',
          y: 'center'
        },
        xAxis: [{
          type: 'category',
          data: temp.xData
        }],
        yAxis: [
          { type : 'value',name:'单位(个)',splitLine: false},
          {
            type: 'value',
            name:'通过率',
            axisLabel : {formatter: '{value} %'},
            min: 0,
            max: 100,
          }
        ],
        series: [
        	{name:'发布版本总数',type:'bar',data:temp.totalNum},
        	{name:'一次性通过版本数',type:'bar',data:temp.num},
        	{name:'打回次数',type:'bar',data:temp.backNum},
        	{name:'一次性通过率',type:'line',data:temp.passRate,yAxisIndex: 1},
        ]
      };
		}
	}
})();